package controlLayer;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * The test class DVDControllerTest.
 *
 * @author  Gruppe E
 * @version 1.0
 */
public class DVDControllerTest
{
    /**
     * Default constructor for test class DVDControllerTest
     */
    public DVDControllerTest()
    {
    }

    /**
     * Sets up the test fixture.
     *
     * Called before every test case method.
     */
    @Before
    public void setUp()
    {
    }

    /**
     * Tears down the test fixture.
     *
     * Called after every test case method.
     */
    @After
    public void tearDown()
    {
    }

    /**
     * Method testCreateDVD
     * 
     * Tests CreateDVD
     *
     */
    @Test
    public void testCreateDVD()
    {
        controlLayer.DVDController dVDContr1 = new controlLayer.DVDController();
        assertEquals(true, dVDContr1.createDVD("123", "test", "test", "test"));
        assertEquals(false, dVDContr1.createDVD("123", "test", "test", "test"));
        assertEquals(true, dVDContr1.deleteDVD("123"));
    }

    /**
     * Method testUpdateDVD
     * 
     * Tests UpdateDVD
     *
     */
    @Test
    public void testUpdateDVD()
    {
        controlLayer.DVDController dVDContr1 = new controlLayer.DVDController();
        assertEquals(true, dVDContr1.createDVD("123", "test", "test", "test"));
        assertEquals(false, dVDContr1.updateDVD("234", "test", "test", "test", "345"));
        assertEquals(true, dVDContr1.updateDVD("123", "test", "test", "test", "789"));
        assertEquals(true, dVDContr1.deleteDVD("789"));
    }

    /**
     * Method testDeleteDVD
     * 
     * Tests DeleteDVD
     *
     */
    @Test
    public void testDeleteDVD()
    {
        controlLayer.DVDController dVDContr1 = new controlLayer.DVDController();
        assertEquals(true, dVDContr1.createDVD("123", "test", "test", "test"));
        assertEquals(false, dVDContr1.deleteDVD("234"));
        assertEquals(true, dVDContr1.deleteDVD("123"));
    }

    /**
     * Method testFindDVD
     * 
     * Tests FindDVD
     *
     */
    @Test
    public void testFindDVD()
    {
        controlLayer.DVDController dVDContr1 = new controlLayer.DVDController();
        assertEquals(true, dVDContr1.createDVD("123", "test", "test", "test"));
        assertNotNull(dVDContr1.findDVD("123"));
        assertNull(dVDContr1.findDVD("234"));
        assertEquals(true, dVDContr1.deleteDVD("123"));
    }

    /**
     * Method testCreateCopy
     * 
     * Tests CreateCopy
     *
     */
    @Test
    public void testCreateCopy()
    {
        controlLayer.DVDController dVDContr1 = new controlLayer.DVDController();
        assertEquals(true, dVDContr1.createDVD("abc", "test", "test", "test"));
        assertEquals("confirmed", dVDContr1.createCopy("abc", "123", "test", 123)); //opret copy
        assertEquals("invalidBarcode", dVDContr1.createCopy("abba", "123", "test", 123)); //opret copy med en DVD der ikke eksisterer
        assertEquals(true, dVDContr1.isHome("abc", "123")); //tjekker om copy er hjemme
        assertEquals("copyExists", dVDContr1.createCopy("abc", "123", "test", 123)); //opret samme copy
        assertEquals(true, dVDContr1.deleteCopy("abc", "123"));
        assertEquals(true, dVDContr1.deleteDVD("abc"));
    }

    /**
     * Method testUpdateCopy
     * 
     * Tests UpdateCopy
     *
     */
    @Test
    public void testUpdateCopy()
    {
        controlLayer.DVDController dVDContr1 = new controlLayer.DVDController();
        assertEquals(true, dVDContr1.createDVD("abc", "test", "test", "test"));
        assertEquals("confirmed", dVDContr1.createCopy("abc", "123", "test", 123));
        assertEquals(false, dVDContr1.updateCopy("abc", "234", "345", "test", 123, true)); //opdater copy med forkert serilaNumber
        assertEquals(false, dVDContr1.updateCopy("bcd", "123", "345", "test", 123, true)); //opdater copy med forkert barcode
        assertEquals(true, dVDContr1.updateCopy("abc", "123", "789", "test", 123, true)); //opdater copy med rigtige parametre
        assertEquals(true, dVDContr1.deleteCopy("abc", "789"));
        assertEquals(true, dVDContr1.deleteDVD("abc"));
    }

    /**
     * Method testFindCopy
     * 
     * Tests FindCopy
     *
     */
    @Test
    public void testFindCopy()
    {
        controlLayer.DVDController dVDContr1 = new controlLayer.DVDController();
        assertEquals(true, dVDContr1.createDVD("abc", "test", "test", "test"));
        assertEquals("confirmed", dVDContr1.createCopy("abc", "123", "test", 123));
        assertNotNull(dVDContr1.findCopy("abc", "123")); //find rigtig copy
        assertNull(dVDContr1.findCopy("bcd", "123")); //find copy med forkert barcode
        assertNull(dVDContr1.findCopy("abc", "234")); //find copy med forkert serialNumber
        assertEquals(true, dVDContr1.deleteCopy("abc", "123"));
        assertEquals(true, dVDContr1.deleteDVD("abc"));
    }

    /**
     * Method testDeleteCopy
     * 
     * Tests DeleteCopy
     *
     */
    @Test
    public void testDeleteCopy()
    {
        controlLayer.DVDController dVDContr1 = new controlLayer.DVDController();
        assertEquals(true, dVDContr1.createDVD("abc", "test", "test", "test"));
        assertEquals("confirmed", dVDContr1.createCopy("abc", "123", "test", 123));
        assertEquals(false, dVDContr1.deleteCopy("bcd", "123")); //slet med forkert barcode
        assertEquals(false, dVDContr1.deleteCopy("abc", "234")); //slet med forkert serialNumber
        assertEquals(true, dVDContr1.deleteCopy("abc", "123")); //slet med rigtigt barcode og serialNumber
        assertEquals(true, dVDContr1.deleteDVD("abc"));
    }
}